<template>
    <el-container>
      <el-collapse-transition>
          <div v-show="show3">
          <el-aside width="500px">
              <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
                <el-form-item label="待诊患者名称：" prop="name">
                  <el-input
                    v-model="queryParams.name"
                    placeholder="待诊请输入患者名称"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                  />
                  <el-form-item>
                    <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                  </el-form-item>
                </el-form-item>
                <div style="background-color:#23beff;height: 40px; color: #0505ff;border-radius: 4px; line-height: 38px">待诊患者</div>
                <el-table v-loading="loading" :data="registrationList" @selection-change="handleSelectionChange" >
                  <el-table-column label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column label="姓名" align="center" prop="name" />
                  <el-table-column label="年龄" align="center" prop="patientAgeStr"/>
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['dms:registration:edit']"
                      >就诊</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <br/>
                <div style="background-color:#adff75;height: 40px; color: rgba(0,136,17,1);border-radius: 4px; line-height: 38px">诊中患者</div>
                <el-table v-loading="loading" :data="registrationList2" @selection-change="handleSelectionChange" >
                  <el-table-column label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column label="姓名" align="center" prop="name" />
                  <el-table-column label="年龄" align="center" prop="patientAgeStr"/>
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['dms:registration:edit']"
                      >就诊</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <br/>
                <div style="background-color:rgba(255,0,4,0.29);height: 40px; color: rgb(255,0,3);border-radius: 4px; line-height: 38px">患者诊毕</div>
                <el-table v-loading="loading" :data="registrationList3" @selection-change="handleSelectionChange" >
                  <el-table-column label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column label="姓名" align="center" prop="name" />
                  <el-table-column label="年龄" align="center" prop="patientAgeStr"/>
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['dms:registration:edit']"
                      >就诊</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <br/>
                <div style="background-color:rgba(255,242,21,0.15);height: 40px; color: rgb(199,190,0);border-radius: 4px; line-height: 38px">患者已退号</div>
                <el-table v-loading="loading" :data="registrationList4" @selection-change="handleSelectionChange" >
                  <el-table-column label="病历号" align="center" prop="medicalRecordNo" />
                  <el-table-column label="姓名" align="center" prop="name" />
                  <el-table-column label="年龄" align="center" prop="patientAgeStr"/>
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['dms:registration:edit']"
                      >就诊</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <!-- 添加或修改就诊(门诊)信息对话框 -->
                <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
                  <el-form ref="form" :model="form" :rules="rules" label-width="95px">
                    <el-form-item label="医生的排班id" prop="skdId">
                      <el-input v-model="form.skdId" placeholder="请输入就诊医生ID开始确诊" style="margin-left: 5px;"/>
                    </el-form-item>
                  </el-form>
                  <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                  </div>
                </el-dialog>
              </el-form>
          </el-aside>
          </div>
      </el-collapse-transition>
      <div @click="show3 = !show3">
        <el-main>Main</el-main>
        </div>
    </el-container>
</template>

<script>
  import { listRegistration, getRegistration, delRegistration, addRegistration, updateRegistration, exportRegistration } from "@/api/dms/registration";

export default {
  name: "Registration",
  data() {
    return {
      show3: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 就诊(门诊)信息表格数据
      registrationList: [],
      registrationList2: [],
      registrationList3: [],
      registrationList4: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
       queryParams: {
         status: 1
      },
      queryParams2: {
        status: 2
      },
      queryParams3: {
        status: 3
      },
      queryParams4: {
        status: 4
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
    };

  },
  created() {
    this.getList();
    this.getList2();
    this.getList3();
    this.getList4();
  },
  methods: {
    /** 查询就诊(门诊)信息列表 */
    getList() {
      this.loading = true;
      listRegistration(this.queryParams).then(response => {
        this.registrationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList2() {
      this.loading = true;
      listRegistration(this.queryParams2).then(response => {
        this.registrationList2 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList3() {
      this.loading = true;
      listRegistration(this.queryParams3).then(response => {
        this.registrationList3 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getList4() {
      this.loading = true;
      listRegistration(this.queryParams4).then(response => {
        this.registrationList4 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        patientId: null,
        createTime: null,
        endAttendance: null,
        status: 0,
        skdId: null,
        needBook: null,
        bindStatus: 0,
        deptId: null,
        attendanceDate: null,
        patientAgeStr: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加就诊(门诊)信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRegistration(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改就诊(门诊)信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRegistration(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addRegistration(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除就诊(门诊)信息编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delRegistration(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有就诊(门诊)信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportRegistration(queryParams);
      }).then(response => {
        this.download(response.msg);
      }).catch(function() {});
    }
  }
};
</script>
